//
//  AuctionCollectionHeaderBtnsView.m
//  MyNewProject
//
//  Created by 王春辉 on 2019/12/23.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "AuctionCollectionHeaderBtnsView.h"

@interface AuctionCollectionHeaderBtnsView()

@property (nonatomic, copy) AuctionCollectionHeaderBtnsViewClickBlock block;
@end
@implementation AuctionCollectionHeaderBtnsView
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupContentViews];
    }
    return self;
}

/**
 设置subViews
 */
- (void)setupContentViews {
    NSArray <NSString *>*imageNames = @[@"auction_header_hall_btn_img",
                                        @"auction_header_treasure_hall_btn_img",
                                        @"auction_header_score_shoping_btn_img",
                                        @"auction_header_deal_log_list_btn_img"
                                        ];
    NSArray <NSString *>*titles = @[@"拍卖大厅",
                                    @"精选拍场",
                                    @"积分商城",
                                    @"成交记录"
                                    ];
    
    for (int i = 0; i < imageNames.count; i++) {
        NSString *title = titles[i];
        NSString *imageName = imageNames[i];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:SKIMAGE_NAMED(imageName) forState:UIControlStateNormal];
        [btn setImage:SKIMAGE_NAMED(imageName) forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i;
        [self addSubview:btn];
        UILabel *label = [[UILabel alloc] init];
        label.textColor = SKColorWithHex(0x333333);
        label.font = SKFONT_BOLD_SIZE(15);
        label.textAlignment = NSTextAlignmentCenter;
        label.text = title;
        [self addSubview:label];
        CGFloat lable_w = label.intrinsicContentSize.width;
        CGFloat margin = 10.0;
        CGFloat centerMargin = (SCREEN_WIDTH - 15 - 15 - margin * 2 - lable_w * imageNames.count) / (imageNames.count - 1);
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(margin + i * (centerMargin + lable_w));
            make.bottom.mas_offset(0);
            make.height.mas_equalTo(14.5);
        }];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(label);
            make.top.mas_offset(0);
            make.bottom.mas_equalTo(label.mas_top).mas_offset(-10);
            make.width.mas_equalTo(btn.mas_height);
        }];
    }
}

#pragma mark -- mark EVENT


/**
 button点击事件

 @param sender sender
 */
- (void)buttonClick:(UIButton *)sender {
    if (self.block) {
        self.block(sender.tag); }
}

/**
 按钮点击事件回调block
 
 @param block block
 */
- (void)buttonsClickBlock:(AuctionCollectionHeaderBtnsViewClickBlock)block {
    self.block = block;
}
@end
